﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.Serialization;
namespace GSLMS.Entity
{
	/// <summary>
	/// 表汇总信息
	/// </summary>
	[DataContract(IsReference = true)]
	public partial class TB_TABLEINFO: IObjectWithChangeTracker, INotifyPropertyChanged
	{
		public TB_TABLEINFO()
		{}
		#region Model
		private string _tablename;
		private long _startno;
		private long _nextno;
		private int _tablecount;
		private int _deletecount;
		private int _actioncount;
		private Nullable<DateTime> _lastactiondate;
		private int _actionflag;
		/// <summary>
		/// 表名,主键，唯一
		/// </summary>
		[DataMember]
		public string TABLENAME
		{
			get{return _tablename;}
			set{
				if ( _tablename!= value)
				{
					if (ChangeTracker.ChangeTrackingEnabled && ChangeTracker.State != ObjectState.Added)
					{
						throw new InvalidOperationException("属性“TABLENAME”是对象键的一部分，不可更改。仅当未跟踪对象或对象处于“已添加”状态时，才能对键属性进行更改。");
					}
					 _tablename = value;
					OnPropertyChanged("TABLENAME");
				}
			}
		}
		/// <summary>
		/// 起始记录ID
		/// </summary>
		[DataMember]
		public long STARTNO
		{
			get{return _startno;}
			set{
				if ( _startno!= value)
				{
					 _startno = value;
					OnPropertyChanged("STARTNO");
				}
			}
		}
		/// <summary>
		/// 下一记录ID
		/// </summary>
		[DataMember]
		public long NEXTNO
		{
			get{return _nextno;}
			set{
				if ( _nextno!= value)
				{
					 _nextno = value;
					OnPropertyChanged("NEXTNO");
				}
			}
		}
		/// <summary>
		/// 表记录数
		/// </summary>
		[DataMember]
		public int TABLECOUNT
		{
			get{return _tablecount;}
			set{
				if ( _tablecount!= value)
				{
					 _tablecount = value;
					OnPropertyChanged("TABLECOUNT");
				}
			}
		}
		/// <summary>
		/// 已删除记录数
		/// </summary>
		[DataMember]
		public int DELETECOUNT
		{
			get{return _deletecount;}
			set{
				if ( _deletecount!= value)
				{
					 _deletecount = value;
					OnPropertyChanged("DELETECOUNT");
				}
			}
		}
		/// <summary>
		/// 操作次数
		/// </summary>
		[DataMember]
		public int ACTIONCOUNT
		{
			get{return _actioncount;}
			set{
				if ( _actioncount!= value)
				{
					 _actioncount = value;
					OnPropertyChanged("ACTIONCOUNT");
				}
			}
		}
		/// <summary>
		/// 最后操作时间
		/// </summary>
		[DataMember]
		public Nullable<DateTime> LASTACTIONDATE
		{
			get{return _lastactiondate;}
			set{
				if ( _lastactiondate!= value)
				{
					 _lastactiondate = value;
					OnPropertyChanged("LASTACTIONDATE");
				}
			}
		}
		/// <summary>
		/// 最后操作类型,1新增，2编辑，3删除
		/// </summary>
		[DataMember]
		public int ACTIONFLAG
		{
			get{return _actionflag;}
			set{
				if ( _actionflag!= value)
				{
					 _actionflag = value;
					OnPropertyChanged("ACTIONFLAG");
				}
			}
		}
		#endregion Model

	#region ChangeTracking
	   
	protected virtual void OnPropertyChanged(String propertyName)
	{
	    if (ChangeTracker.State != ObjectState.Added && ChangeTracker.State != ObjectState.Deleted)
	    {
	        ChangeTracker.State = ObjectState.Modified;
	    }
	    if (_propertyChanged != null)
	    {
	        _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
	    }
	}
	   
	protected virtual void OnNavigationPropertyChanged(String propertyName)
	{
	    if (_propertyChanged != null)
	    {
	        _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
	    }
	}
	   
	event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged{ add { _propertyChanged += value; } remove { _propertyChanged -= value; } }
	private event PropertyChangedEventHandler _propertyChanged;
	private ObjectChangeTracker _changeTracker;
	   
	[DataMember]
	public ObjectChangeTracker ChangeTracker
	{
	    get
	    {
	        if (_changeTracker == null)
	        {
	            _changeTracker = new ObjectChangeTracker();
	            _changeTracker.ObjectStateChanging += HandleObjectStateChanging;
	        }
	        return _changeTracker;
	    }
	    set
	    {
	        if(_changeTracker != null)
	        {
	            _changeTracker.ObjectStateChanging -= HandleObjectStateChanging;
	        }
	        _changeTracker = value;
	        if(_changeTracker != null)
	        {
	            _changeTracker.ObjectStateChanging += HandleObjectStateChanging;
	        }
	    }
	}
	   
	private void HandleObjectStateChanging(object sender, ObjectStateChangingEventArgs e)
	{
	    if (e.NewState == ObjectState.Deleted)
	    {
	        ClearNavigationProperties();
	    }
	}
	   
	protected bool IsDeserializing { get; private set; }
	   
	[OnDeserializing]
	public void OnDeserializingMethod(StreamingContext context)
	{
	    IsDeserializing = true;
	}
	   
	[OnDeserialized]
	public void OnDeserializedMethod(StreamingContext context)
	{
	    IsDeserializing = false;
	    ChangeTracker.ChangeTrackingEnabled = true;
	}
	   
	protected virtual void ClearNavigationProperties()
	{
	}
	
	#endregion

	}
}

